<?php

/**
 * @autdor aisyah
 * @copyright 2012
 */

include_once "header.php";


echo "<div class='container'>
<div class='row'>";
include_once "sidebar.php";

echo "<div class='span9'>";
 
require_once "../dao/blog_dao.php";
require_once "../dao/comment_dao.php";

$modul=$_GET['modul'];
$id=$_GET['id'];
$breadcrump ="";

$blog = new Blog_Dao($class_db);

$comment = new Comment_Dao($class_db);
include "../../config/paging.php";
        //$modul = "category";
        //$modul_name = $id;
        $p = new Paging;
        
switch($modul){
    
    default :  
        
        
        $batas = 10;
        $posisi = $p->cari_posisi($batas);
        //print_r($posisi.",".$batas);
        
        $blog->db->show_Data("blog","*",$posisi,$batas);
        
        $jmldata = count($blog->hasil);
        
        $blogg = $blog->db->hasil;
        
        //var_dump($blogg);
        
        if($blogg!=null) {
            
           foreach($blogg as $data) {
            
            $tanggal = new Tanggal($data['date']);
            
            $tgl = $tanggal->get_tgl_indo();
            
            $content = $blog->list_content($data['content'],$data['blog_id']);
            
            echo "
            
            <div class='span8 well pull-left'><table>                
                ";
            
            echo "
                <tr valign = top>
                    <td colspan=9 style='color:blue;font-weight:bold'>$data[title]</td></tr>
                    <tr valign = top><td colspan=9><img src='../../images/clock.gif'> $tgl | Kontributor : $data[contributor]</td></tr>
                    <tr valign = top><td colspan=9>Rating : $data[rating]</td></tr>
                    <tr valign = top><td><div class=span2><image src='../../images/blog/$data[image]'></div></td> 
                    <td colspan=9>$content</td></tr>
                                                            
                    
                ";
                
            echo "            
            </table></div><div></div>
            ";        
            
            }
            
            echo "<div class=span8>";
            
            $blog->db->hasil = "";
            $blog->db->show_Data('blog');
            $jml_data = count($blog->db->hasil);
            //print_r($jml_data);
            $jml_halaman = $p->jml_halaman($jml_data,$batas);
            //print_r($jml_halaman);
            
            $link_halaman = $p->navHalaman(null, $_GET['halaman'],$jml_halaman);
            
            echo $link_halaman;
            
            echo "</div>"; 
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
        
        //print_r($data);        {
        
        
        
         
        
    break;
    
    case "tampil":   
        
    
        $blog->db->show_Data('blog','*',null,null,'blog_id='.$id);
        
        $blogg = $blog->db->hasil;
        
        //var_dump($blogg);
        $modul2 = $modul."&id=".$id;
        
        if($blogg!=null) {
            
           foreach($blogg as $data) {
            
            $tanggal = new Tanggal($data['date']);
            
            $tgl = $tanggal->get_tgl_indo();
    
        echo "<div class='span8 well pull-left'><table>     
                <tr valign = top>
                    <td colspan=9 style='color:blue;font-weight:bold'>$data[title]</td></tr>
                    <tr valign = top><td colspan=9><img src='../../images/clock.gif'> $tgl | Kontributor : $data[contributor]</td></tr>
                    <tr valign = top><td colspan=9>Rating : $data[rating]</td></tr>
                    <tr valign = top><td><image src='../../images/blog/$data[image]'></td> 
                    <td colspan=9>$data[content]</td></tr>            
            </table></div>";
            
            //bagian KOMENTAR
            echo "<div class='span8 well pull-left'><h2>Komentar</h2></br>";
            
            $batas = 15;
            $posisi = $p->cari_posisi($batas);
            //print_r($posisi.",".$batas);
            
            $comment->db->show_Data('comment','*',$posisi,$batas,'blog_id='.$id);
            
            $komentar = $comment->db->hasil;
            if($komentar!=null){
                foreach($komentar as $data1){
                    
                    $tanggal->set_tgl($data1['date']);
                    $tgl = $tanggal->get_tgl_indo();
                    
                    echo "<table>     
                        <tr valign = top>                            
                            <tr valign = top><td colspan=9 style='color:blue;font-weight:bold'>$data1[name] | <img src='../../images/clock.gif'> $tgl </td></tr>
                            <td colspan=9><i>$data1[comment]</i></td></tr>            
                        </table></br>";
                }
                
                echo "<div>";
            
            $comment->db->hasil = "";
            $comment->db->show_Data('comment');
            $jml_data = count($comment->db->hasil);
            //print_r($jml_data);
            $jml_halaman = $p->jml_halaman($jml_data,$batas);
            //print_r($jml_halaman);
            
            $link_halaman = $p->navHalaman($modul2, $_GET['halaman'],$jml_halaman);
            
            echo $link_halaman;
            
            echo "</div>";
            }
            
            //dibawah ini bagian form menambah komentar
            //belum dibuat captcha-nya
            echo "</div><div class='span6 well pull-left'><h2>Tambah Komentar</h2></br>";
            echo "
                <form method='POST' action='blog_aksi.php?modul=tambah_comment' enctype='multipart/form-data'>
                <input type='hidden' value='$id' name='id' >
                <table>
                <tr><td>Nama</td><td><input type=text name='name' size=30 placeholder='Nama Pemberi Komentar'></td></tr>
                <tr><td>Email</td><td><input type=text name='email' size=30 placeholder='Email - tidak dipublikasi'></td></tr>
                <tr><td valign=top>Komentar</td><td><textarea name='comment'  style='width: 300px; height: 150px;' placeholder='komentar anda'></textarea></td></tr>
                <tr><td valign=top>&nbsp;</td><td><img src='../../config/captcha.php'></td></tr>
                <tr><td valign=top>&nbsp;</td><td>(Masukkan 6 kode di atas)</td></tr>
                <tr><td valign=top>&nbsp;</td><td><input type='text' name='kode' size=6></td></tr>
                <tr><td><td colspan=2><input class='btn btn-primary pull-left' type=submit value=Simpan>
                            </td></tr>
                </table>
                </form></div>
            ";
            }
        }else{
            echo "<tr><td colspan=5 align=center>DATA TIDAK DITEMUKAN</td></tr>";
        }
        
    break;
    
    case "tambah";
        
        //use tambah tulisan blg belum selesai, 
        //masih membutuhkan kelas upload dan sesi user
        //rencananya pakai sesi trus ngambil nama asli user.
        
        $isi = "Silahkan tulis isi blog disini, panjang karakter minimal 600 huruf";
        
        echo "
                <form method=POST action='blog_aksi.php?modul=tambah' enctype=multipart/form-data>
                <table>
                <tr><td>Judul</td><td><input type=text name=title size=50 placeholder='judul blog'></td></tr>
                <tr><td valign=top>Isi Blog</td><td><textarea name='content'  style='width: 600px; height: 350px;' placeholder='$isi'></textarea></td></tr>
                <tr><td>Gambar</td><td><input type=file name=image></td></tr>                
                <tr><td><td colspan=2><input type=submit value=Simpan>
                            <input type=button value=Batal onclick=self.history.back()></td></tr>
                </table>
                </form>
            ";
    break;    
    
    
    
    
}

echo "</div>";
echo "</div>";
echo "</div>";

include_once "footer.php";